package util;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.context.FacesContext;

public class ADFUtil {

    public static void setEL(String el, Object val) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext elContext = facesContext.getELContext();
        ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
        ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
        exp.setValue(elContext, val);
    }
    
    public static Object invokeEL(String el, Class[] paramTypes,
      Object[] params) {
      FacesContext facesContext = FacesContext.getCurrentInstance();
      ELContext elContext = facesContext.getELContext();
      ExpressionFactory expressionFactory =
      facesContext.getApplication().getExpressionFactory();
      MethodExpression exp =
      expressionFactory.createMethodExpression(elContext, el,
      Object.class, paramTypes);
      
      return exp.invoke(elContext, params);
      }
    
    public static Object invokeEL(String el) {
      return invokeEL(el, new Class[0], new Object[0]);
      }
}

